<?php
function PropertiesBuildRoute( &$query )
{
       $segments = array();	   
	  
       if(isset($query['view']))
       {		
	   			 $segments[] = $query['view'];
                unset( $query['view'] );	
				
				if(isset($query['format']))
       {
	   				
					/*if(isset($query['option']))
      				 {
					$segments[] = $query['option'];
               		 unset( $query['option'] );
					}*/
					
                $segments[] = $query['format'];
                unset( $query['format'] );
       }
	   if(isset($query['type']))
       {
                $segments[] = $query['type'];
                unset( $query['type'] );
       }
	  
	   
	   
	   
               			
       }	 
	    
		
	   if(isset($query['task']))
	   {
	  
	  			if($query['task'] == 'agentlisting'){
					$segments[] = $query['task'];
               		unset( $query['task'] );
	   					if(isset($query['aid']))
      					 {
           			     $segments[] = $query['aid'];
          			      unset( $query['aid'] );
      					 }				
				
				}else{
				$segments[] = $query['task'];
                unset( $query['task'] );
				}
		}
		
		
				
		
	
	   
	   if(isset($query['cid']))
       {
                $segments[] = $query['cid'];
                unset( $query['cid'] );
       }
	   if(isset($query['tid']))
       {
                $segments[] = $query['tid'];
                unset( $query['tid'] );
       }
       if(isset($query['id']))
       {	   				
                $segments[] = $query['id'];
                unset( $query['id'] );				
       }	

	    if(isset($query['srart']))
       {	   				
                $segments[] = $query['srart'];
                unset( $query['srart'] );				
       }	
	  if(isset($query['layout']))
       {
              //  $segments[] = $query['layout'];
                unset( $query['layout'] );
       }	
	   
	    
	   
	  /* if(isset($query['option']))
       {
                $segments[] = $query['option'];
                unset( $query['option'] );
       }*/
	 /* echo 'entre';   
	   $nombre_archivo = 'components\com_properties\fabio_routerS.txt';
$gestor = fopen($nombre_archivo, 'w');
$contenido = 'segments 0 : '. $segments[0]."\n";
$contenido .= 'segments 1 : '. $segments[1]."\n";
$contenido .= 'segments 2 : '. $segments[2]."\n";
$contenido .= 'segments 3 : '. $segments[3]."\n";
$contenido .= 'segments 4 : '. $segments[4]."\n";



 fwrite($gestor, $contenido);
  
  
  print_r($segments);
  */
       return $segments;
}

function PropertiesParseRoute( $segments )
{
       $vars = array();	   
	   $count = count( $segments );
       switch($segments[0])
       {
               case 'property':
                       $vars['view'] = 'property';                     
					  $vars['cid'] = $segments[1];
					  $vars['tid'] = $segments[2];
					   $vars['id'] = $segments[3];					 
                       break;
								
				case 'properties':					   
					   $vars['view'] = 'properties';            
					  $vars['cid'] = $segments[1];
					  $vars['tid'] = $segments[2];
					  $vars['id'] = $segments[3];		
					   			 
                       break;
					   
				case 'profile':
                       $vars['view'] = 'profile';					 
                       break;
					   
				case 'panel':
                      $vars['view'] = 'panel';					
					  $vars['task'] = $segments[1];					
					  $vars['id'] = $segments[2];					  			  
                       break;
				case 'search':
					  $vars['task'] = 'search';		
					  $vars['view'] = 'properties';
                       break;
				case 'addlightbox':
					  $vars['task'] = 'addlightbox';
					  $vars['id'] = $segments[1];
                       break;
				case 'agentlisting':
					  $vars['task'] = 'agentlisting';
					  $vars['aid'] = $segments[1];
                       break;
				case 'shortlist':
					  $vars['view'] = 'shortlist';	
					  $vars['task'] = $segments[1];	
					  $vars['id'] = $segments[2];			  
                       break;
				
					   	   
				default:
				/*$vars['cid'] = $segments[0];*/
				break;
                                      
       }	 
	   
/*
	   $nombre_archivo = 'components\com_properties\fabio_router.txt';
$gestor = fopen($nombre_archivo, 'a');
$contenido = 'segments 0 : '. $segments[0]."\n";
$contenido .= 'segments 1 : '. $segments[1]."\n";
$contenido .= 'segments 2 : '. $segments[2]."\n";
$contenido .= 'segments 3 : '. $segments[3]."\n";
$contenido .= 'segments 4 : '. $segments[4]."\n";
$contenido .= 'segments 5 : '. $segments[5]."\n";
$contenido .= 'uri : '. $_SERVER['HTTP_REFERER']."\n";
fwrite($gestor, $contenido);

print_r($vars);
print_r($segments);
 */ 
 
  
  
       return $vars;
}